<?php

namespace app\model\store;

use app\model\delivery\PostageTemplate;
use app\model\site\Site;
use think\Model;

class Goods extends Model
{

    public function site(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(Site::class, 'site_id');
    }

    // 分类
    public function cates(): \think\model\relation\BelongsToMany
    {
        return $this->belongsToMany(GoodsCate::class, 'goods_cate_rel', 'cate_id', 'goods_id');
    }
    // 标签
    public function tags(): \think\model\relation\BelongsToMany
    {
        return $this->belongsToMany(GoodsTag::class, 'goods_tag_rel', 'tag_id', 'goods_id');
    }
    // 商品sku
    public function skus (): \think\model\relation\HasMany
    {
        return $this->hasMany(GoodsSku::class, 'goods_id', 'id');
    }
    // 规格
    public function specs(): \think\model\relation\HasMany
    {
        return $this->hasMany(GoodsSpec::class, 'goods_id');
    }

    // 评论
    public function replies(): \think\model\relation\HasMany
    {
        return $this->hasMany(GoodsReply::class, 'goods_id');
    }

    // 运费模板
    public function postageTpl(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(PostageTemplate::class, 'postage_tpl_id');
    }
}
